<template>
    <div class="mui-numbox" data-numbox-min='1' style="height: 25px;">
        <button class="mui-btn mui-btn-numbox-minus" type="button">-</button>
        <input id="test" class="mui-input-numbox" type="number" :value="initCount" @change="countChanged" ref="numbox" readonly/>
        <button class="mui-btn mui-btn-numbox-plus" type="button">+</button>
    </div>
</template>

<script>
//导入mui
import mui from '../../lib/mui/js/mui.min.js'
export default {
    data() {
        return {

        }
    },
    methods: {
        countChanged() {    
           //每当数量改变把最新的数据同步到store中 覆盖原先的值
           this.$store.commit('updateShopCarWithGoods',{
               id: this.goodsId,
               count: this.$refs.numbox.value
           })
        }
    },
    props: [
        'initCount',
        'goodsId'
    ],
    mounted() {
        //初始化数字选择框
        mui('.mui-numbox').numbox()
    }
}
</script>

<style lang="scss" scoped>

</style>